package com.mz361.modules.system.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mz361.common.enums.StatusEnum;
import com.mz361.common.utils.StatusUtil;
import lombok.Data;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author liaomch
 * @date 2024/05/07
 */
@Data
@Entity
@Table(name = "std_member")
@EntityListeners(AuditingEntityListener.class)
@Where(clause = StatusUtil.NOT_DELETE)
public class CMember implements Serializable {
    // 主键ID
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    //用户名称，系统生成不可修改
    private String name;
    // 盐度
    private String salt;
    // 用户密码
    @JsonIgnore
    private String password;
    //用户昵称，系统生成可修改
    private String nickname;
    // 用户的渠道平台ID
    @JsonIgnore
    private String idCode;
    // 用户的身份证
    @JsonIgnore
    private String idCard;
    // 用户电话
    private String phone;
    // 级别
    public String level;
    // 类别 1:个人用户；2:企业用户
    public String type;
    //openid
    @JsonIgnore
    public String openid;
    // 用户头像
    private String head;
    // 性别
    private String sex;
    // 生日
    @JsonIgnore
    private String birthday;
    // 邮箱
    @JsonIgnore
    private String email;
    // 邀请码
    @JsonIgnore
    private String inviteCode;
    // 渠道ID
    @Column(name = "source_id")
    private Long sourceId;
    private String sourceName;
    @ManyToOne
    @JoinColumn(insertable = false, updatable = false, name = "source_id", referencedColumnName = "id")
    @JsonIgnore
    @NotFound(action = NotFoundAction.IGNORE)
    private CSource csource;
    // 企业ID
    @Column(name = "company_id")
    private Long companyId;
    private String companyName;
    @ManyToOne
    @JoinColumn(insertable = false, updatable = false, name = "company_id", referencedColumnName = "id")
    @JsonIgnore
    @NotFound(action = NotFoundAction.IGNORE)
    private Company company;

    // 创建时间
    @CreatedDate
    private Date createDate;
    // 更新时间
    @LastModifiedDate
    private Date updateDate;
    // 创建者
    @CreatedBy
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "create_by")
    @JsonIgnore
    private User createBy;
    // 更新者
    @LastModifiedBy
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "update_by")
    @JsonIgnore
    private User updateBy;
    // 数据状态
    private Byte status = StatusEnum.OK.getCode();

}